package 分布式事务.事务A;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import 分布式事务.事务A.daoA.WorkADao;
import 分布式事务.事务A.daoB.WorkBDao;
import 分布式事务.事务A.entity.TbWorkA;
import 分布式事务.事务A.entity.TbWorkB;

import java.util.List;

/**
 * @author caihe
 * @date 2022/3/15 19:18
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {WorkApplicationA.class})
@ComponentScan("分布式事务")
@Configuration
public class WorkApplicationTestA {

    @Autowired
    private WorkADao workADao;
    @Autowired
    private WorkBDao workBDao;
    
    @Test
    @Transactional
    public void workA() {
        // 还是需要在一个jvm里面才成立
        workADao.insert("事务测试A 002");
        int a = 1 / 0;
        workBDao.insert("事务测试B 002");

        List<TbWorkA> tbWorkAS = workADao.selectAll();
        List<TbWorkB> tbWorkBS = workBDao.selectAll();

        System.out.println();
    }

}
